package day05_api.com.itheima.d2_lambda;

import day05_api.com.itheima.d1_array.Student;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.IntToDoubleFunction;

public class LambdaTest2 {
    public static void main(String[] args) {
        double[] scores = {100, 80, 70, 60, 50, 90, 60, 30, 22,90};
        Arrays.setAll(scores, new IntToDoubleFunction() {
            @Override
            public double applyAsDouble(int value) {
                return scores[value] + 10;
            }
        });

        Arrays.setAll(scores, (int index) -> scores[index] + 10);

        Arrays.setAll(scores, index -> scores[ index] + 10);

        System.out.println("Arrays.toString(scores) = " + Arrays.toString(scores));
        System.out.println("--------------------");

        Student[] students = new Student[4]; // students = [null, null, null, null]
        //                                                   0     1     2     3
        students[0] = new Student("周芷若", 21, '女', 169.3);
        students[1] = new Student("殷素素", 38, '女', 172.2);
        students[2] = new Student("小昭", 19, '女', 168.5);
        students[3] = new Student("张无忌", 23, '男', 183.5);

        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        Arrays.sort(students,(o1, o2) -> {
            return o1.getAge() - o2.getAge();
        });

        Arrays.sort(students, (o1, o2) -> o1.getAge() - o2.getAge());

        System.out.println("Arrays.toString(students) = " + Arrays.toString(students));

    }
}
